# -*- coding: utf-8 -*-  
#!/usr/bin/python2.7
"""File的抽象，并且针对mako模板引擎"""

__authors__ = [
  '"BigYuki" <sheyuqi@gmail.com>',
] 
import web
import mimetypes

class StaticFile:
    """针对web.py，返回静态文件。"""
    def __init__(self,filePath):
        self.contentType=mimetypes.guess_type(filePath)[0]
        self.cotent=self.__read(filePath)
        
    def read(self):
        web.header("Content-Type", self.contentType)
        return self.cotent
    
    def __read(self, filePath):
        try:
            f = open(filePath, 'rb')
            return f.read()
        except:
            raise web.NotFound()